package com.xidian.zhiancloud.service.user.usermanage;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xidian.zhiancloud.dao.syset.usermanage.OrganizationMapper;
import com.xidian.zhiancloud.model.syset.Organization;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 组织机构
 */
@Service
public class OrganizationService extends ServiceImpl<OrganizationMapper, Organization> {

    @Autowired
    OrganizationMapper organizationMapper;

    public Organization selectByNameAndOrglevelid(Long companyId,String name, Integer orglevelid){
        return organizationMapper.selectByNameAndOrglevelid(companyId,name,orglevelid);
    }

    public void addOrgMessage(Organization org){
        organizationMapper.addOrgMessage(org);
    }

    public Organization selectByName(Long companyId,String name){
        return organizationMapper.selectByName(companyId,name);
    }

    public Organization selectById(Long companyId,Long id){
        return organizationMapper.selectByIdAndCompanyId(companyId, id);
    }

    public List<Organization> getById(Long companyId,String id){
        return organizationMapper.getById(companyId,id);
    }

    //查询公司中的安全部门
    public Organization getByIsafeorg(Long companyId){
        return organizationMapper.getByIsafeorg(companyId);
    }

    public Organization getByTopPid(Long companyId){
        return organizationMapper.getByTopPid(companyId);
    }

    public int deleteOrg(String id){
        List<String> lists = getList(id);
        return organizationMapper.deleteOrg(lists);
    }

    /**
     * id放入list
     * @param id id(多个已逗号分隔)
     * @return List集合
     */
    public List<String> getList(String id) {
        List<String> list = new ArrayList<String>();
        String[] str = id.split(",");
        for (int i = 0; i < str.length; i++) {
            list.add(str[i]);
        }
        return list;
    }

    public void updateOrgMessage(String id,Organization org){
        organizationMapper.updateOrgMessage(id,org);
    }


    public List<Organization> getByLeadUserid(){
        String o = "1,2,3";
        List<String> orgList=Arrays.asList(o.split(","));
        return organizationMapper.getByLeadUserid(1L, orgList);
    }

}
